var functions = require("../../functions.js");
var see_view_list_fun = require("../../utils/see_view_list.js");
//获取应用实例
var app = getApp()
var allUserList = [];
var searchUserList2 = [];
var start = 0;//被查看列表的开始数
var isLoading = 0;
Page({

  data: {
    searchUserList: {}
  },

  onLoad: function () {
    start = 0;
    allUserList = [];
    searchUserList2 = [];
    functions.getJiLu(start, this.showData);
    wx.showToast({
      title: '加载数据中',
      icon: 'loading',
      duration: 100000
    })
  },

  onPullDownRefresh:function(){
    allUserList = [];
    searchUserList2 = [];
    start = 0;
    functions.getJiLu(start, this.showData);
  },
  //自定义显示
  showData: function (dataList) {
    for (var i = 0; i < dataList.data.length; i++) {
      allUserList.push(dataList.data[i]);
    }
    if (start < 0) {
      //不操作
    } else {
      start = start + 20;
    }
    //更新数据
    this.setData({
      searchUserList: allUserList
    })
    wx.hideToast()
    isLoading = 0;
    wx.stopPullDownRefresh();
  },

  //点击查看名片
  viewCard: function (e) {
    add_form_id(e.detail.formId)
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '/pages/other/other?openid=' + openid,
    })
  },
  //点击查看名片
  toJiLu: function (e) {
    add_form_id(e.detail.formId)
    wx.navigateTo({
      url: '/pages/jilu/jilu'
    })
  },
  //打电话
  callPhone: function (event) {
    var phone = event.target.dataset.phone;
    if (phone != "") {
      wx.makePhoneCall({
        phoneNumber: phone,
        success: function (res) {
          // success
        }
      })
    }
  },

   //打开我的名片
  openMyCard: function () {
     wx.switchTab({
       url: '/page/index/index',
    });
    
  },
  onReachBottom: function () {
    if (isLoading == 1) {

    } else {
      if (start < 0) {
        //不操作
      }else {
        isLoading = 1;
        wx.showToast({
          title: '加载数据中',
          icon: 'loading',
          duration: 100000
        });
        functions.getJiLu(start, this.showData);
      }
    }
  }

})
//添加form_id
function add_form_id(form_id) {
  wx.request({
    url: app.globalData.API_Base_URL + '/formid/index/setFormId?openid=' + app.globalData.openid + '&formid=' + form_id,
  })
}